package com.project.web.controller.client;

import com.project.client.domain.UserEntity;
import com.project.client.service.UserService;
import com.project.client.vo.UpdateUserPassVo;
import com.project.common.annotation.Log;
import com.project.common.core.controller.BaseController;
import com.project.common.core.domain.AjaxResult;
import com.project.common.core.page.TableDataInfo;
import com.project.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 客户端帐号Controller
 *
 * @author project
 * @date 2021-05-10
 */
@RestController
@RequestMapping("/client/user")
public class UserController extends BaseController {
    @Autowired
    private UserService service;

    /**
     * 查询客户端帐号列表
     */
    @PreAuthorize("@ss.hasPermi('client:user:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserEntity entity) {
        startPage();
        List<UserEntity> list = service.selectList(entity);
        return getDataTable(list);
    }

    /**
     * 获取客户端帐号详细信息
     */
    @PreAuthorize("@ss.hasPermi('client:user:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(service.selectById(id));
    }

    /**
     * 修改客户端帐号
     */
    @PreAuthorize("@ss.hasPermi('client:user:edit')")
    @Log(title = "客户端帐号", businessType = BusinessType.UPDATE)
    @PostMapping("initPassword")
    public AjaxResult initPassword(@RequestBody UpdateUserPassVo vo) {
        return toAjax(service.updatePassword(vo.getId(), vo.getPassword()));
    }

    /**
     * 删除客户端帐号
     */
    @PreAuthorize("@ss.hasPermi('client:user:remove')")
    @Log(title = "客户端帐号", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(service.delete(ids));
    }
}
